package com.mine.modules.vm.controller;


import com.mine.common.domain.vo.Result;
import com.mine.modules.sys.domain.dto.RoleDto;
import com.mine.modules.vm.domain.dto.VmPermissionDto;
import com.mine.modules.vm.service.IVmPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-09
 */
@Slf4j
@Api(tags = "场景菜单管理")
@RestController
@RequestMapping("/vm/menu")
@RequiredArgsConstructor
public class VmPermissionController {

    private final IVmPermissionService permissionService;

    /**
     * 加载数据节点
     *
     */
    @ApiOperation("菜单树形列表")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public Result<?> listAll(@RequestParam(value = "keywords", required = false) String keywords, HttpServletRequest req) {
        return permissionService.listAll(keywords, req);
    }

    @ApiOperation("新增或修改")
    @PostMapping(value = "/addOrEdit")
    public Result<?> addOrEdit(VmPermissionDto permissionDto) {
        return permissionService.addOrEdit(permissionDto);
    }

    @ApiOperation("删除菜单")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        return permissionService.delete(id);
    }

    @ApiOperation("批量删除菜单")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        return permissionService.deleteBatch(ids);
    }

    /**
     * 查询角色授权
     */
    @ApiOperation("查询角色授权")
    @RequestMapping(value = "/queryRolePermission", method = RequestMethod.GET)
    public Result<List<String>> queryRolePermission(@RequestParam(name = "roleId", required = true) String roleId) {
        return permissionService.queryRolePermission(roleId);
    }

    /**
     * 保存角色授权
     */
    @ApiOperation("保存角色授权")
    @RequestMapping(value = "/saveRolePermission", method = RequestMethod.POST)
    public Result<?> saveRolePermission(RoleDto roleDto) {
        return permissionService.saveRolePermission(roleDto);
    }

    @ApiOperation("token查询用菜单")
    @RequestMapping(value = "/getUserPermissionByToken", method = RequestMethod.GET)
    public Result<?> getUserPermissionByToken() {
        return permissionService.getUserPermissionByToken();
    }

}
